home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / basename.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  2.9 KB  |  90 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //  Creation Date:  Sept 22, 1999
  21. //<doc>
  22. //<name basename>
  23. //<owner "Alias|Wavefront Unsupported">
  24. //
  25. //<synopsis>
  26. //        basename(string $path, string $extension)
  27. //
  28. //<description>
  29. //        Strips from $path any prefix ending in '/'. If $path ends in a '/' 
  30. //        it is first stripped. If $suffix is not empty, $suffix will also be 
  31. //        stripped if it exists at the end of $path. On NT, the input $path is 
  32. //        first processed to convert all backslashes ('\', input as "\\") to '/'s.
  33. //
  34. //<flags>
  35. //      string     $path            Path string to strip
  36. //        string     $suffix        Suffix to strip off 
  37. //
  38. //<returns>
  39. //      string: the stripped basename
  40. //
  41. //<examples>
  42. //    string $path = "/usr/people/gamera/gamera.mel";
  43. //    string $basename = basename( $path, ".mel" );
  44. //    // Result: gamera //
  45. //  basename( $path, "" );
  46. //    // Result: gamera.mel //
  47. //  string $ntPath = "C:/aw/godzilla/hello.c";
  48. //    basename( $ntPath, ".c" );
  49. //    // Result: hello //
  50. //
  51. //</doc>
  52. //
  53. global proc string basename( string $path, string $suffix )
  54. {
  55.     if ( `about -nt`  || `about -mac`)
  56.         $path = convert( $path );
  57.  
  58.     // Check to make sure we're not chopping off slash if
  59.     // it's the only path delimiter!
  60.     if ( (match( "^/$", $path ) == "") && // Root dir 
  61.          (match( "^[A-Za-z]:/$", $path ) == "" ) ) // X:/ on NT
  62.     {
  63.         // Strip off last '/', if it exists
  64.         $path = substitute("/$", $path, "");
  65.     }
  66.  
  67.     string $basename;
  68.     // Is this a UNC path?
  69.     if ( match( "^//", $path ) != "" )
  70.     {
  71.         // If so, we check if there is anything after the first 
  72.         // component of the path. If not, we return nothing.
  73.         if ( match( "^//.*/.*", $path ) != "" )
  74.             $basename = match( "[^/]*$", $path );
  75.         else
  76.             return "";
  77.     }
  78.     else // We get everything after the last "/"
  79.         $basename = match("[^/]*$", $path);
  80.  
  81.     // if $suffix is given, replace it (if it's at the end) with ""
  82.     if ( size( $suffix ) != 0 )
  83.     {
  84.         $suffix = $suffix + "$";
  85.         $basename = substitute( $suffix, $basename, "" );        
  86.     }
  87.  
  88.     return $basename;
  89. }
  90.